package user

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'PUT'
        url value(consumer(regex('/api/users/\\d+/detail')), producer('/api/users/1/detail'))
        body("""
             {
                "userId":2,
                "username":"user",
                "password":"1234"
             }
        """)
        body("""
             {
                "userId":1,
                "school": "西安邮电大学",
                "name": "西安邮电",
                "major": "软件工程",
                "degree": "硕士",
                "gender": "F",
                "schoolProvince": "陕西",
                "schoolCity": "西安",
                "entranceYear": "2014"
             }
        """)
        bodyMatchers {
            jsonPath('$.userId', byRegex(number()))
            jsonPath('$.school', byRegex("\\w+"))
            jsonPath('$.name', byRegex("\\w+"))
            jsonPath('$.major', byRegex("\\w+"))
            jsonPath('$.degree', byRegex("\\w+"))
            jsonPath('$.gender', byRegex("[FM]"))
            jsonPath('$.schoolProvince', byRegex("\\w+"))
            jsonPath('$.schoolCity', byRegex("\\w+"))
            jsonPath('$.entranceYear', byRegex(number()))
        }
        headers {
            header('Content-Type': 'application/json;charset=UTF-8')
        }
    }
    response {
        status 204
    }
}
